from django.utils.decorators import method_decorator

from gis.common.django_ext.views import BaseView
from itpay.core.sys import bulletin_service
from itpay.core.agency import agency_service
from itpay.server_agency.decorators import require_login


class BulletinView(BaseView):
    @method_decorator(require_login())
    def get(self, request):
        agency_id = request.user_id
        agency = agency_service.get_agency_by_id(agency_id, with_mch_info=True)
        mch_ids = [e["id"] for e in agency['mchs']] if agency.get('mchs') else None
        c, ls = bulletin_service.list_bulletin(page_no=1, page_size=5, is_flash=True, mch_ids=mch_ids)
        return ls
